<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'
import {isAuth} from '../../../utils'
// import {getFormatDateTime} from '@/utils'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      teamLeadApprovalAuthName: 'order:orderdetail:teamLeadApproval',
      sendOrderLeadApprovalAuthName: 'order:orderdetail:sendOrderLeadApproval',
      boxOrderApprovalAuthName: 'order:orderdetail:boxOrder',
      dataFormConfig: {
        id: {
          hidden: true
        },
        orderNo: {
          label: '订单编号',
          disabled: true
        },
        productId: {
          label: '产品',
          type: 'list',
          filterable: true,
          disabled: true,
          list: [],
          placeholder: '请选择产品',
        },
        unitPrice: {
          label: '单价',
          type: 'number',
          max: 1000,
          min: 0,
          default: 0
        },

        productWeight: {
          label: '克重',
          type: 'number',
          max: 1000
        },
        orderProductNumber: {
          label: '订单数量',
          type: 'number',
          max: 10000000
        },
        productVolume: {
          label: '容量',
          type: 'number',
          max: 1000
        },
/*        deepStatus: {
          label: '光瓶深加工',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 0
        },
        deepCategoryList: {
          reply: () => this.dataForm.deepStatus,
          label: '光瓶深加工方式',
          type: 'listAndNumberAndRadio',
          listPlaceholder: '请选择加工方式',
          numberPlaceholder: '请输入深加工备注（颜色）',
          listName: 'deepCategoryIdList',
          numberName: 'customerRequire',
          radioName: 'purchaseNumber',
          list: []
        },
        deepProductImage: {
          reply: () => this.dataForm.deepStatus,
          label: '光瓶深加工样图',
          type: 'uploadImage',
          imageType: 'uploadProductImage'
        },*/
        customerRequire:{
          label: '规格描述 ',
        },
        pipeRange: {
          label: '管长'
        },
        sampleImage: {
          label: '产品样图',
          type: 'uploadImage',
          imageType: 'uploadProductImage'
        },
        specialMark: {
          label: '箱唛描述',
          placeholder: '请输入箱唛'
        },
        boxPackImage: {label: '箱唛图片',
          type: 'uploadImage',
          imageType: 'uploadProductImage'
        },

        remark: {
          label: '备注',
          inputType: 'textarea',
          placeholder: '请输入备注'
        },
        status: {
          label: '订单状态',
          list: [],
          type: 'list'
        },

      }
    }
  },
  methods: {
    /**
     * 初始化瓶配信息列表
     * @param attrName 瓶配信息属性名
     */
    initBottleSuitList(attrName = 'bottleSuitList') {
      mRequest('systemApi/getSysDictLabelTreeList', {}, (res) => {
        this.dataFormConfig[attrName].list = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    /**
     * 成模数量变化时的回调
     */
    /**
     * 产品选择后的回调
     * @param value 选择的产品
     */
    productSelectCallback(value) {
      if (window.R.isNil(value)) {
        return
      }
      mRequest('productApi/productInfoInfo', {id: value}, (res) => {
        const productInfo = this.R.path(['data', 'productInfo'], res)

        this.dataForm['modelId'] = productInfo['modelId']
        this.dataForm['productWeight'] = productInfo['productWeight']
        // this.dataForm['deepStatus'] = this.R.gt(this.R.length(productInfo['deepCategoryList']), 0) ? 1 : 0
        // this.dataForm['deepCategoryList'] = productInfo['deepCategoryList']
        //   this.dataForm['bottleInDiameter'] = productInfo['bottleInDiameter']
        this.dataForm['bottleOutDiameter'] = productInfo['bottleOutDiameter']
        this.dataForm['bottleCapSuit'] = productInfo['productAssort']
        this.dataForm['weightScope'] = this.R.isNil(productInfo['weightScope']) ? '±' : productInfo['weightScope']
        this.dataForm['headNeckHeight'] = productInfo['headNeckHeight']
        this.dataForm['productVolume'] = productInfo['productVolume']
        this.dataForm['volumeScope'] = this.R.isNil(productInfo['volumeScope']) ? '±' : productInfo['volumeScope']
        this.dataForm['deviceId'] = productInfo['deviceId']
        this.dataForm['bottleLength'] = productInfo['bottleLength']
        this.dataForm['bottleWeight'] = productInfo['bottleWeight']
        this.dataForm['bottleHeight'] = productInfo['bottleHeight']
      })
    },
    modelIdSelectCallback() {
      if (window.R.isEmpty(this.dataForm.modelId)) {
        this.dataForm.leftSuccessMo = 0
        this.dataForm.leftPrimaryMo = 0
        this.dataForm.leftJiaZi = 0
        this.dataForm.leftKouZi = 0
        this.dataForm.leftLengQue = 0
        this.dataForm.leftLouDou = 0
        this.dataForm.leftMenTou = 0
        this.dataForm.leftQiTou = 0
        this.dataForm.leftXinZi=0
        return
      }
      mRequest('modelApi/modelInfoInfo', {id: this.dataForm.modelId}, (res) => {
        const {data} = res
        const {modelInfo} = data
        const {successMo, primaryMo, jiaZi, kouZi, lengQue, louDou, menTou, qiTou, xinZi} = modelInfo
        this.dataForm.leftSuccessMo = successMo
        this.dataForm.leftPrimaryMo = primaryMo
        this.dataForm.leftJiaZi = jiaZi
        this.dataForm.leftKouZi = kouZi
        this.dataForm.leftLengQue = lengQue
        this.dataForm.leftLouDou = louDou
        this.dataForm.leftMenTou = menTou
        this.dataForm.leftQiTou = qiTou
        this.dataForm.leftXinZi = xinZi
      })
    },
    init(id, property,cb) {
      this.dataForm.id = id || 0
   //   this.initBottleSuitList()
      this.initDeepCategoryList('deepCategoryList')

  //    this.initModelInfoList('modelId')
      this.initProductInfoList()
      this.initTradeOrderStatusList('status')
      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        stepsConfig: this.stepsConfig,
        dataRule: this.getNeedDataRule('orderTime', 'clientId', 'deliveryTime', 'productId', 'deviceId', 'orderProductNumber', 'boxSupplyWay', 'productWeight', 'boxNumber', 'trayNumber', 'deepStatus', 'deepType', 'customerProductStyle', 'bottleCapSuit', 'bottleLength', 'bottleWeight', 'bottleHeight', 'packRequire', 'status'),
        initApi: 'orderApi/orderDetailInfo',
        saveApi: 'orderApi/saveOrderDetail',
        updateApi: 'orderApi/updateOrderDetail',
        objectName: 'orderDetail',
        submitCallback: cb
      })

      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            this.dataForm[key] = property[key]
          })
        }
      })
    }
  }
}
</script>
